﻿package com.tudou.home.view.ad
{
    import com.tudou.ad.components.*;
    import com.tudou.ad.consts.*;
    import com.tudou.ad.data.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.model.*;
    import com.tudou.home.view.ad.base.*;
    import com.tudou.skin.*;
    import flash.display.*;
    import flash.events.*;

    public class AdCptFloatMediator extends AdBaseMediator implements IAdMediator
    {
        private var floatBox:InfoCloseButton;
        private var floatAdObj:Object;
        public static const NAME:String = "AdCptFloatMediator";

        public function AdCptFloatMediator()
        {
            super(NAME, null);
            return;
        }// end function

        override public function showAd() : void
        {
            if (floatBox)
            {
                floatBox.visible = true;
            }
            return;
        }// end function

        override public function getAdDisplay() : DisplayObject
        {
            return floatBox;
        }// end function

        private function clickHandler(event:Event) : void
        {
            if (event.type == InfoCloseButton.CLOSE)
            {
                hideAd();
                sendNotification(AdCommandSet.AD_CPT_FLOAT_CLOSE);
            }
            else
            {
                sendNotification(AdCommandSet.AD_CPT_FLOAT_CLICK);
            }
            return;
        }// end function

        override public function setAdDisplay(param1:DisplayObject, param2:DisplayObject = null) : void
        {
            return;
        }// end function

        override public function hideAd() : void
        {
            if (floatBox)
            {
                floatBox.visible = false;
            }
            return;
        }// end function

        private function cptAdItemInfo() : IAdItemInfo
        {
            var _loc_1:* = "<ads aid=\"" + floatAdObj.throwId + "\" lk=\"" + floatAdObj.link + "\" id=\"" + floatAdObj.positionId + "\" n=\"\"" + " m=\"\" oid=\"" + floatAdObj.ownerId + "\" p=\"0.0\" type=\"" + AdType.CPT_FLOAT + "\" mtype=\"1\" mode=\"1\" d=\"0\" dt=\"0\"" + " su=\"\" ufo=\"\" scu=\"\" title=\"" + floatAdObj.content + "\" ftitle=\"\" flink=\"\"> </ads>";
            return new AdItemInfo(new XML(_loc_1));
        }// end function

        public function setAdObj(param1:Object) : Boolean
        {
            var link:String;
            var adObj:* = param1;
            try
            {
                if (adObj != null && adObj.floatAdv != null && adObj.floatAdv != "" && adObj["floatAdv"].hasOwnProperty("link"))
                {
                    link = String(adObj.floatAdv.link);
                    if (link != null && link != "undefined" && link != "" && link != "null")
                    {
                        _adThrowInfo = new AdThrowInfo();
                        _adThrowInfo.areaCode = adObj.areaCode;
                        _adThrowInfo.channel = PageInfo.getInstance().channelId;
                        floatAdObj = adObj.floatAdv;
                        _adItemInfo = cptAdItemInfo();
                        floatBox = new InfoCloseButton(new GetMoreBTN(), new GetMoreCloseBTN());
                        if (_adItemInfo.title != null && _adItemInfo.title != "" && _adItemInfo.title != "undefined")
                        {
                        }
                        floatBox.addEventListener(InfoCloseButton.CLICK, clickHandler);
                        floatBox.addEventListener(InfoCloseButton.CLOSE, clickHandler);
                        return true;
                    }
                }
            }
            catch (e:Error)
            {
                return false;
            }
            return false;
        }// end function

    }
}
